package com.controller;

import com.model.VenderDevice;
import com.page.GenericPage;
import com.po.ProductPO;
import com.po.VenderDeviceModifyPO;
import com.po.VenderDevicePO;
import com.po.VenderDeviceQueryPO;
import com.result.Result;
import com.service.ProductService;
import com.service.VenderDeviceService;
import com.vo.DeviceInfoVO;
import com.vo.ProductVO;
import com.vo.VenderDeviceQueryVO;
import com.vo.VenderDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 14:14
 * @Version 1.0
 * @Note  租赁车设备控制层
 */


@Api(value = "venderDeviceApi")
@CrossOrigin
@RestController
@RequestMapping("/venderDevice")
public class VenderDeviceController {

    @Autowired
    private VenderDeviceService venderDeviceService;

    //ProductVO
    @ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<VenderDeviceQueryVO> save(@RequestBody VenderDevicePO venderDevicePO) {
        return venderDeviceService.save(venderDevicePO);
    }


    //ProductVO
    @ApiOperation(value = "删除", httpMethod = "GET", notes = "删除")
    @RequestMapping(value = "/removeById", method = RequestMethod.GET)
    public Result<Boolean> removeById(@RequestParam Long id) {
        return venderDeviceService.removeById(id);
    }



    @ApiOperation(value = "修改", httpMethod = "POST", notes = "修改")
    @RequestMapping(value = "/modifyById", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<Boolean> modifyById(@RequestBody VenderDeviceModifyPO venderDeviceModifyPO) {
        return venderDeviceService.modifyById(venderDeviceModifyPO);
    }

    @ApiOperation(value = "查询", httpMethod = "GET", notes = "查询")
    @RequestMapping(value = "/queryByID", method = RequestMethod.GET)
    public Result<VenderDeviceQueryVO> queryByID(@RequestParam Long id) {
        return venderDeviceService.queryById(id);
    }



    @ApiOperation(value = "查询", httpMethod = "POST", notes = "查询")
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<GenericPage<VenderDeviceVO>> queryAll(@RequestBody VenderDeviceQueryPO venderDeviceModifyPO) {
        return venderDeviceService.queryAll(venderDeviceModifyPO);
    }

    /**
     * 查询当前用户的设备列表
     */
    @ApiOperation(value = "查询当前用户的设备列表", httpMethod = "GET", notes = "查询当前用户的设备列表")
    @RequestMapping(value = "/queryAll", method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public Result<List<VenderDeviceVO>> getMineDeviceList(){
        return venderDeviceService.getMineDevieList();
    }


    ///////////////////////////////一条华丽的分割线//////////////////////////////////

    /**
     * 获取设备详情
     */
    @ApiOperation(value = "获取设备详情", httpMethod = "GET", notes = "获取设备详情")
    @RequestMapping(value = "/queryDeviceDetailInfo", method = RequestMethod.GET)
    public Result<VenderDeviceQueryVO> queryDeviceDetailInfo(@RequestParam Long id) {
        return venderDeviceService.queryById(id);
    }


    /**
     * 获取设备详情
     */
    @ApiOperation(value = "获取设备详情", httpMethod = "GET", notes = "获取设备详情")
    @RequestMapping(value = "/queryDeviceDetailInfoBySn", method = RequestMethod.GET)
    public Result<DeviceInfoVO> queryDeviceDetailInfoBySn(@RequestParam String sn) {
        return venderDeviceService.queryDeviceDetailInfoBySn(sn);
    }

    /**
     * 获取设备详情
     */
    @ApiOperation(value = "获取设备详情并提交应用版本", httpMethod = "GET", notes = "获取设备详情并提交应用版本")
    @RequestMapping(value = "/queryDeviceDetailInfoBySnAndHandleAppVersion", method = RequestMethod.GET)
    public Result<DeviceInfoVO> queryDeviceDetailInfoBySnAndHandleAppVersion(@RequestParam String sn,@RequestParam String appVersion) {
        return venderDeviceService.queryDeviceDetailInfoBySnAndHandleAppVersion(sn,appVersion);
    }


}
